package com.css.crm.vo;

import java.util.Date;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.css.crm.utility.DateUtil;

@XmlRootElement(name = "customer-discount")
public class CustomerDiscountVo extends AuditTrailVo {

	/** CUST_DISC_ID **/
	private Long custDiscId;
	/** CUST_ID **/
	private String custId;
	/** DISC_CDE **/
	private String discCde;
	/** EXPIRY_DTE **/
	private Date expiryDte;
	/** DFLT_IND **/
	private String defltInd;

	@XmlElement
	public String getCustId() {
		return custId;
	}

	public void setCustId(String custId) {
		this.custId = custId;
	}

	@XmlElement
	public String getDiscCde() {
		return discCde;
	}

	public void setDiscCde(String discCde) {
		this.discCde = discCde;
	}

	@XmlElement
	public Date getExpiryDte() {
		return expiryDte;
	}

	public void setExpiryDte(Date expiryDte) {
		this.expiryDte = expiryDte;
	}

	@XmlElement
	public String getDefltInd() {
		return defltInd;
	}

	public void setDefltInd(String defltInd) {
		this.defltInd = defltInd;
	}

	public Long getCustDiscId() {
		return custDiscId;
	}

	public void setCustDiscId(Long custDiscId) {
		this.custDiscId = custDiscId;
	}
	
	@Override
	public int compareTo(AuditTrailVo o) {
		CustomerDiscountVo vo = (CustomerDiscountVo) o;
		if(vo == null){
			//if not set original data, default set to modified.
			return 1;
		}
		String custId = this.getCustId() == null ? "" : this.getCustId();
		String discCode = this.getDiscCde() == null ? "" : this.getDiscCde();
		String expireDate = DateUtil.formatDate(this.getExpiryDte());
		expireDate = expireDate == null?"":expireDate;
		
		String custIdCompareTo = vo.getCustId() == null ? "" : vo.getCustId();
		String discCodeCompareTo = vo.getDiscCde() == null ? "" : vo.getDiscCde();
		String expireDateCompareTo = DateUtil.formatDate(vo.getExpiryDte());
		expireDateCompareTo = expireDateCompareTo == null?"":expireDateCompareTo;

		// check if have any field be modified
		int result = 0;
		if (!custId.equals(custIdCompareTo)) {
			result = 1;
		}
		if (!discCode.equals(discCodeCompareTo)) {
			result = 1;
		}
		if (!expireDate.equals(expireDateCompareTo)) {
			result = 1;
		}
		return result;
	}

}
